<template>
  <div>
    <el-card class="box-card" style="width: 600px;margin: auto">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="渠道名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="appid" prop="appid">
        <el-select v-model="form.appid">
          <el-option v-for="a in appids" :key="a.id" :value="a.id" :label="a.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="系统版本" prop="versionsId">
        <el-select v-model="form.versionsId">
          <el-option v-for="v in versionsIds" :key="v.id" :value="v.id" :label="v.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="渠道选择" prop="typeId">
        <el-select v-model="form.typeId">
          <el-option v-for="t in typeIds" :key="t.id" :value="t.id" :label="t.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="渠道号">
        <el-input v-model="form.qudao"></el-input>
      </el-form-item>
      <el-form-item label="公司名称" prop="firmId">
        <el-select v-model="form.firmId">
          <el-option v-for="f in firmIds" :key="f.id" :value="f.id" :label="f.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save">保存</el-button>
      </el-form-item>
    </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'SaveView',
  data () {
    return {
      appids: [],
      versionsIds: [],
      typeIds: [],
      firmIds: [],
      form: {
        name: '',
        appid: null,
        versionsId: null,
        typeId: null,
        qudao: '',
        firmId: null
      }
    }
  },
  methods: {
    save () {
      this.axios.post('/channel/save', this.form).then(res => {
        if (res.data.code === 200) {
          this.$message.success('添加成功')
          this.$router.push('/list')
        }
      })
    }
  },
  created () {
    // appid下拉框
    this.axios.get('/center/list', { params: { type: 1 } }).then(res => {
      if (res.data.code === 200) {
        this.appids = res.data.jdata
      }
    })
    // 系统版本下拉框
    this.axios.get('/center/list', { params: { type: 2 } }).then(res => {
      if (res.data.code === 200) {
        this.versionsIds = res.data.jdata
      }
    })
    // 渠道选择下拉框
    this.axios.get('/center/list', { params: { type: 3 } }).then(res => {
      if (res.data.code === 200) {
        this.typeIds = res.data.jdata
      }
    })
    // 公司下拉框
    this.axios.get('/center/list', { params: { type: 4 } }).then(res => {
      if (res.data.code === 200) {
        this.firmIds = res.data.jdata
      }
    })
  }
}
</script>

<style scoped>

</style>
